import request from "@/utils/request";
import qs from 'qs'
//获取小说列表
export function bookList(query) {
  return request({
    url:'/book/admin/book/list',
    method:'get',
    params:query
  })
}

export function getBookById(bookId){
  return request({
    url:`/book/admin/getBookById/${bookId}`,
    method:'get'
  })
}

//修改小说状态
export function changeBookStatus(bookId,status){
  var formData = new FormData;
  formData.append("id",bookId);
  formData.append("status",status)
  return request({
    url:'/book/admin/category/changeBookStatus',
    method:'post',
    data:formData
  })
}
//获取当前小说的分类
export function currentCategory(bookId) {
  return request({
    url:`/book/admin/book/currentCategory/${bookId}`,
    method:'get',
  })
}

//获得没有添加到该小说下的分类
export function unaddCategory(bookId){
  return request({
    url:`/book/admin/book/unaddCategory/${bookId}`,
    method:'get'
  })
}

//修改分类
export function updateCategory(query){
  return request({
    url:'/book/admin/book/updateInfo',
    method:'post',
    data:query
  })
}

//根据id删除小说
export function deleteById(ids){
  const query={
    ids:ids
  }
  return request({
    url:'/book/admin/book/deleteById',
    method:'delete',
    params:query,
    paramsSerializer:function (params) {
      return qs.stringify(params,{ arrayFormat: "repeat" })
    }
  })
}

//根据小说id查看小说的章节信息
export function readNovelIndex(query){
  return request({
    url:'/book/bookIndex/listBookIndex',
    method:'post',
    data:query
  })
}

//查询小说部分信息和章节的详细信息
export function bookIndex(query){
  return request({
    url:`/book/bookIndex`,
    method:'get',
    params:query
  })
}

//修改收费状态
export function changeIsVip(isVip,id){
  const data = {
    isVip,
    id
  }
  return request({
    url:'/book/admin/changeIsVip',
    method:'post',
    data:data
  })
}

//删除小说章节
export function deleteBookIndex(bookId,indexIds){
  const query = {
    bookId,
    indexIds
  }
  console.log(query)
  return request({
    url:'/book/admin/deleteIndecies',
    method:'delete',
    params:query,
    paramsSerializer:function (params) {
      return qs.stringify(params,{arrayFormat:"repeat"})
    }
  })
}

//清空小说章节
export function clearBookIndex(bookId){
  return request({
    url:`/book/admin/clearBookIndex/${bookId}`,
    method:'delete',
  })
}

//修改小说信息
export function updateBook(data){
  return request({
    url:'/book/admin/updateBook',
    method:'post',
    data:data
  })
}

//通过分类id，禁用该分类下的所有小说
export function disableBookByCategory(categoryId){
  return request({
    url:`/book/admin/disableBookByCategory/${categoryId}`,
    method:'post',
  })
}
